#include "peonyrabbitvcsemblems.h"

#include "../peony-rabbitvcs-menu/statuschecker.h"

PeonyRabbitVCSEmblems::PeonyRabbitVCSEmblems(QObject *parent)
    : QObject(parent)
{
}

Peony::EmblemProvider *PeonyRabbitVCSEmblems::create()
{
    return new RabbitVCSEmblemProvider(this);
}


RabbitVCSEmblemProvider::RabbitVCSEmblemProvider(QObject *parent) : EmblemProvider(parent)
{

}

const QString RabbitVCSEmblemProvider::emblemKey()
{
    return "rabbit-vcs";
}

QStringList RabbitVCSEmblemProvider::getFileEmblemIcons(const QString &uri)
{
    if (uri.startsWith("file:///")) {
        QString tmp = uri;
        tmp.remove(0, 7);
        QString result = StatusChecker::getInstance()->checkStatus(tmp, true, true, true);
        QStringList resultList = result.split(",");
        QString test = resultList.count() >= 2? resultList.at(1): nullptr;
        if (!test.isEmpty()) {
            resultList = test.split(":");
            result = resultList.last();
            result.remove('\"');
            if (result.isEmpty()) {
                return QStringList();
            }
            return QStringList()<<StatusChecker::getInstance()->getStatusIconName(result);
        }
        return QStringList();
    } else {
        return QStringList();
    }
}
